package com.xbongbong.paas.service.init;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.dao.PaasPrintTemplateDao;
import com.xbongbong.paas.domain.entity.PaasAppEntity;
import com.xbongbong.paas.domain.entity.PaasFormEntity;
import com.xbongbong.paas.domain.entity.PaasMenuEntity;
import com.xbongbong.paas.domain.entity.PaasPrintTemplateEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.DelEnum;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.model.PaasAppModel;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.model.PaasMenuModel;
import com.xbongbong.paas.pojo.FormTitlePoJo;
import com.xbongbong.paas.pojo.SummaryDataPoJo;
import com.xbongbong.paas.pojo.dto.ApplicationAddDTO;
import com.xbongbong.paas.pojo.dto.ApplicationUpdateDTO;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import com.xbongbong.paas.service.ProAppService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.helper.ReflectHelper;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.pro.app.pojo.dto.ApplicationAddBatchDTO;
import com.xbongbong.pro.app.pojo.vo.ApplicationAddBatchVO;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.constant.MenuConstant;
import com.xbongbong.pro.enums.AccessLinkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.WorkReportEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.menu.enums.ProductMenuEnum;
import com.xbongbong.pro.enums.menu.enums.SystemAppMenuEnum;
import com.xbongbong.pro.menu.pojo.MenuReturnPojo;
import com.xbongbong.pro.menu.pojo.dto.MenuInitDTO;
import com.xbongbong.pro.menu.pojo.vo.MenuInitVO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.domain.entity.FundAccountEntity;
import com.xbongbong.saas.enums.OnlinePaymentFlowDistributorEnum;
import com.xbongbong.saas.enums.PayBalanceEnum;
import com.xbongbong.saas.enums.PrintTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.AssembleEnum;
import com.xbongbong.saas.enums.business.BomBillEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.CommunicatePlanEnum;
import com.xbongbong.saas.enums.business.CompetitorAnalysisEnum;
import com.xbongbong.saas.enums.business.CompetitorEnum;
import com.xbongbong.saas.enums.business.ContactEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import com.xbongbong.saas.enums.business.ContractOutstockEnum;
import com.xbongbong.saas.enums.business.CostAdjustEnum;
import com.xbongbong.saas.enums.business.CreditCardBillEnum;
import com.xbongbong.saas.enums.business.CreditFixedLimitEnum;
import com.xbongbong.saas.enums.business.CreditLimitEnum;
import com.xbongbong.saas.enums.business.CreditTemporaryLimitEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import com.xbongbong.saas.enums.business.DistributorAccountEnum;
import com.xbongbong.saas.enums.business.DistributorContactEnum;
import com.xbongbong.saas.enums.business.DistributorEnum;
import com.xbongbong.saas.enums.business.ExpenseEnum;
import com.xbongbong.saas.enums.business.FundTransferEnum;
import com.xbongbong.saas.enums.business.InstockEnum;
import com.xbongbong.saas.enums.business.InventoryEnum;
import com.xbongbong.saas.enums.business.InvoiceEnum;
import com.xbongbong.saas.enums.business.MarketActivityEnum;
import com.xbongbong.saas.enums.business.OtherExpenseEnum;
import com.xbongbong.saas.enums.business.OtherIncomeEnum;
import com.xbongbong.saas.enums.business.OutstockEnum;
import com.xbongbong.saas.enums.business.PayPlanEnum;
import com.xbongbong.saas.enums.business.PaySheetEnum;
import com.xbongbong.saas.enums.business.PaymentBalanceEnum;
import com.xbongbong.saas.enums.business.PaymentEnum;
import com.xbongbong.saas.enums.business.PaymentSheetEnum;
import com.xbongbong.saas.enums.business.PaymentTaskEnum;
import com.xbongbong.saas.enums.business.ProductEnum;
import com.xbongbong.saas.enums.business.ProductionInstockEnum;
import com.xbongbong.saas.enums.business.ProductionMaterielOutstockEnum;
import com.xbongbong.saas.enums.business.ProductionOrderEnum;
import com.xbongbong.saas.enums.business.PurchaseEnum;
import com.xbongbong.saas.enums.business.PurchaseInstockEnum;
import com.xbongbong.saas.enums.business.PurchaseInvoiceEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import com.xbongbong.saas.enums.business.ReceiptOrderEnum;
import com.xbongbong.saas.enums.business.RefundEnum;
import com.xbongbong.saas.enums.business.RefundInstockEnum;
import com.xbongbong.saas.enums.business.ReimbursementFormEnum;
import com.xbongbong.saas.enums.business.ReturnedMaterielInstockEnum;
import com.xbongbong.saas.enums.business.ReturnedPurchaseEnum;
import com.xbongbong.saas.enums.business.ReturnedPurchaseOutstockEnum;
import com.xbongbong.saas.enums.business.SalesOpportunityEnum;
import com.xbongbong.saas.enums.business.SupplierContactEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import com.xbongbong.saas.enums.business.TransferEnum;
import com.xbongbong.saas.enums.business.WarehouseEnum;
import com.xbongbong.saas.enums.business.WorkOrderOutstockEnum;
import com.xbongbong.saas.model.FundAccountModel;
import com.xbongbong.sys.enums.UserConfigEnum;
import com.xbongbong.sys.model.CompanyConfigModel;
import com.xbongbong.sys.model.MirrorCompanyModel;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/1/28 15:28
 * @since v1.0
 */
@Component
public abstract class AbstractInitMenuHelp implements InitMenuService {

    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractInitMenuHelp.class);

    @Resource
    private PaasAppModel paasAppModel;
    @Resource
    private ProAppService proAppService;
    @Resource
    private PaasPrintTemplateDao paasPrintTemplateDao;
    @Resource
    private FundAccountModel fundAccountModel;
    @Resource
    private CompanyConfigModel companyConfigModel;
    @Resource
    private PaasMenuModel paasMenuModel;
    @Resource
    private MirrorCompanyModel mirrorCompanyModel;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private PaasRedisHelper paasRedisHelper;

    @Override
    public MenuInitVO open(MenuInitDTO menuInitDTO) throws XbbException {
        Map<String, PaasAppEntity> appMap = addApp(menuInitDTO);
        MenuInitVO menuInitVO = initApp(menuInitDTO, appMap);
        // 清楚当前登录人权限缓存
        if (!StringUtil.isEmpty(menuInitDTO.getCorpid()) && !StringUtil.isEmpty(menuInitDTO.getUserId())) {
            String userKey = menuInitDTO.getCorpid() + "____" + menuInitDTO.getUserId();
            paasRedisHelper.removeValue(RedisPrefixConstant.PAAS_LOGIN_USER_INFO, userKey);
        }
        menuInitVO.setAppMap(appMap);
        return menuInitVO;
    }

    /**
     * 增加应用
     * @author 吴峰
     * @date 2019/2/20 17:49
     * @param menuInitDTO
     * @return com.xbongbong.pro.menu.pojo.dto.MenuInitDTO
     * @throws XbbException 业务异常
     */
    protected Map<String, PaasAppEntity> addApp(MenuInitDTO menuInitDTO) throws XbbException {
        try {
            // 新建应用
            Map<String, PaasAppEntity> appMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            PaasAppEntity paasAppEntity = paasAppModel.getByAlias(menuInitDTO.getAlias(), menuInitDTO.getCorpid());
            if (Objects.nonNull(paasAppEntity)) {
                if (Objects.equals(paasAppEntity.getAlias(), XbbRefTypeEnum.SEARCH_CUSTOMER.getAlias())) {
                    appMap.put(paasAppEntity.getAlias(), paasAppEntity);
                    menuInitDTO.setAppMap(appMap);
                    return appMap;
                }
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, I18nMessageUtil.getMessage(MessageConstant.APP_HAS_BEEN_OPEN));
            }
            paasAppModel.validateCallCenter(menuInitDTO.getCorpid(), menuInitDTO.getAlias());
            if(SystemAppMenuEnum.CRM.getAlias().equals(menuInitDTO.getAlias()) ||
                    SystemAppMenuEnum.JXC.getAlias().equals(menuInitDTO.getAlias())) {
                Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                param.put("corpid", menuInitDTO.getCorpid());
                List<String> aliasIn = new ArrayList<>();
                aliasIn.add(SystemAppMenuEnum.PRODUCT.getAlias());
                aliasIn.add(SystemAppMenuEnum.FUND_MANAGEMENT.getAlias());
                param.put("aliasIn", aliasIn);
                param.put("del", DelEnum.NORMAL.getDel());
                List<PaasAppEntity> appList = paasAppModel.findEntitys(param);
                if(Objects.isNull(appList)) {
                    throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
                }

                appList.forEach((item)->{
                    appMap.put(item.getAlias(), item);
                });
            }
            ApplicationAddBatchDTO applicationAddBatchDTO = new ApplicationAddBatchDTO();
            BeanUtil.copyProperties(menuInitDTO, applicationAddBatchDTO);
            List<ApplicationAddDTO> insertAppList = new ArrayList<>();
            ApplicationAddDTO applicationAddDTO = new ApplicationAddDTO();
            BeanUtil.copyProperties(menuInitDTO, applicationAddDTO);
            SystemAppMenuEnum systemAppMenuEnum = SystemAppMenuEnum.getSystemAppMenuEnum(menuInitDTO.getAlias());
            AccessLinkEnum accessLinkEnum = systemAppMenuEnum.getAccessLinkEnum();
            applicationAddDTO.setIcon(accessLinkEnum.getIcon());
            applicationAddDTO.setColor(accessLinkEnum.getColor());
            applicationAddDTO.setName(systemAppMenuEnum.getName());
            insertAppList.add(applicationAddDTO);
            if(SystemAppMenuEnum.CRM.getAlias().equals(menuInitDTO.getAlias()) ||
                    SystemAppMenuEnum.JXC.getAlias().equals(menuInitDTO.getAlias())) {
                if (!appMap.containsKey(SystemAppMenuEnum.PRODUCT.getAlias())) {
                    insertAppList.add(getProductApp(menuInitDTO));
                }
                if (!appMap.containsKey(SystemAppMenuEnum.FUND_MANAGEMENT.getAlias())) {
                    insertAppList.add(getFundManagement(menuInitDTO));
                }
            }
            if (SystemAppMenuEnum.DISTRIBUTOR.getAlias().equals(menuInitDTO.getAlias())) {
                if (!appMap.containsKey(SystemAppMenuEnum.MARKETING_MANAGEMENT.getAlias())) {
                    insertAppList.add(getInsertApp(menuInitDTO, SystemAppMenuEnum.MARKETING_MANAGEMENT, 1));
                }
                if (!appMap.containsKey(SystemAppMenuEnum.ORDER_CENTER.getAlias())) {
                    insertAppList.add(getInsertApp(menuInitDTO, SystemAppMenuEnum.ORDER_CENTER, 0));
                }
            }
            applicationAddBatchDTO.setAppList(insertAppList);
            ApplicationAddBatchVO applicationAddBatchVO = proAppService.addBatchPaasApp(applicationAddBatchDTO);
            if (Objects.isNull(applicationAddBatchVO)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
            }
            List<PaasAppEntity> resultList = applicationAddBatchVO.getAppList();
            resultList.forEach((item)->{
                appMap.put(item.getAlias(), item);
            });
            menuInitDTO.setAppMap(appMap);
            return appMap;
        } catch (XbbException e) {
            LOGGER.error("MenuInitHelp.menuInit初始化菜单出错", e);
            throw e;
        } catch (Exception e) {
            LOGGER.error("MenuInitHelp.menuInit初始化菜单出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
    }

    /**
     * 获取产品查询的应用数据
     * @author 吴峰
     * @date 2019/2/20 17:48
     * @param menuInitDTO
     * @return com.xbongbong.paas.pojo.dto.ApplicationAddDTO
     * @throws XbbException 业务异常
     */
    public ApplicationAddDTO getProductApp(MenuInitDTO menuInitDTO){
        ApplicationAddDTO applicationAddDTO = new ApplicationAddDTO();
        applicationAddDTO.setCorpid(menuInitDTO.getCorpid());
        applicationAddDTO.setName(SystemAppMenuEnum.PRODUCT.getName());
        applicationAddDTO.setAlias(SystemAppMenuEnum.PRODUCT.getAlias());
        AccessLinkEnum accessLinkEnum = SystemAppMenuEnum.PRODUCT.getAccessLinkEnum();
        applicationAddDTO.setColor(accessLinkEnum.getColor());
        applicationAddDTO.setIcon(accessLinkEnum.getIcon());
        applicationAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
        applicationAddDTO.setDisplay(0);
        return applicationAddDTO;
    }
    /**
     * 获取资金管理的应用数据
     * @author 吴峰
     * @date 2019/2/20 17:49
     * @param menuInitDTO
     * @return com.xbongbong.paas.pojo.dto.ApplicationAddDTO
     * @throws XbbException 业务异常
     */
    public ApplicationAddDTO getFundManagement(MenuInitDTO menuInitDTO){
        ApplicationAddDTO applicationAddDTO = new ApplicationAddDTO();
        applicationAddDTO.setCorpid(menuInitDTO.getCorpid());
        applicationAddDTO.setName(SystemAppMenuEnum.FUND_MANAGEMENT.getName());
        applicationAddDTO.setAlias(SystemAppMenuEnum.FUND_MANAGEMENT.getAlias());
        AccessLinkEnum accessLinkEnum = SystemAppMenuEnum.FUND_MANAGEMENT.getAccessLinkEnum();
        applicationAddDTO.setColor(accessLinkEnum.getColor());
        applicationAddDTO.setIcon(accessLinkEnum.getIcon());
        applicationAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
        applicationAddDTO.setDisplay(0);
        return applicationAddDTO;
    }


    public ApplicationAddDTO getInsertApp(MenuInitDTO menuInitDTO, SystemAppMenuEnum systemAppMenuEnum, Integer display) {
        ApplicationAddDTO applicationAddDTO = new ApplicationAddDTO();
        applicationAddDTO.setCorpid(menuInitDTO.getCorpid());
        applicationAddDTO.setName(systemAppMenuEnum.getName());
        applicationAddDTO.setAlias(systemAppMenuEnum.getAlias());
        AccessLinkEnum accessLinkEnum = systemAppMenuEnum.getAccessLinkEnum();
        applicationAddDTO.setColor(accessLinkEnum.getColor());
        applicationAddDTO.setIcon(accessLinkEnum.getIcon());
        applicationAddDTO.setSaasMark(SaasMarkEnum.SAAS.getCode());
        applicationAddDTO.setDisplay(display);
        return applicationAddDTO;
    }


    /**
     * 初始化，为公司saas模块增加默认打印模板
     * @param corpid 公司id
     * @param formList 表单列表
     * @param appAlias 应用alias
     */
    public void initDefaultPrintTemplates(String corpid,List<PaasFormEntity> formList,String appAlias, Integer distributorMark){
        List<PrintTemplateTypeEnum> printTemplateTypeList = PrintTemplateTypeEnum.getAllEnums();
        List<Integer> businessTypeList = new ArrayList<>();
        for (PrintTemplateTypeEnum printTemplateTypeEnum : printTemplateTypeList) {
            if (printTemplateTypeEnum.getApp().equals(appAlias)) {
                businessTypeList.add(printTemplateTypeEnum.getCode());
            }
        }
        Map<String,Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid",corpid);
        param.put("del",0);
        param.put("businessTypeIn",businessTypeList);
        param.put("distributorMark", distributorMark);
        Integer count;

        count = paasPrintTemplateDao.getEntitysCount(param);
        if (count != null && count > 0) {
            // 已有打印模板，结束
            return;
        }
        param.put("corpid", "0");
        param.put("del", DelEnum.NORMAL.getDel());
        List<PaasPrintTemplateEntity> defaultList = paasPrintTemplateDao.findEntitys(param);
        if (defaultList.isEmpty()) {
            // 数据库中没有存在默认模板配置
            return;
        }
        Map<Integer, PaasPrintTemplateEntity> defaultTemplateMap = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        for (PaasPrintTemplateEntity templateEntity : defaultList) {
            defaultTemplateMap.put(templateEntity.getBusinessType(),templateEntity);
        }
        long now = DateTimeUtil.getInt();
        List<PaasPrintTemplateEntity> insertList = new ArrayList<>();
        for (PaasFormEntity paasFormEntity : formList) {
            Integer businessType = paasFormEntity.getBusinessType();
            if (!businessTypeList.contains(businessType)){
                // 无打印的业务跳过；
                continue;
            }
            PaasPrintTemplateEntity defaultEntity = defaultTemplateMap.get(businessType);
            if (defaultEntity == null) {
                continue;
            }
            PaasPrintTemplateEntity paasPrintTemplateEntity = new PaasPrintTemplateEntity();
            paasPrintTemplateEntity.setName(I18nMessageUtil.getMessage(I18nStringConstant.DEFAULT_TEMPLATE));
            paasPrintTemplateEntity.setCorpid(corpid);
            paasPrintTemplateEntity.setAppId(paasFormEntity.getAppId());
            paasPrintTemplateEntity.setMenuId(paasFormEntity.getMenuId());
            paasPrintTemplateEntity.setFormId(paasFormEntity.getId());
            paasPrintTemplateEntity.setCreatorId("0");
            paasPrintTemplateEntity.setAddTime(now);
            paasPrintTemplateEntity.setUpdateTime(now);
            paasPrintTemplateEntity.setBusinessType(businessType);
            paasPrintTemplateEntity.setHtml(defaultEntity.getHtml());
            paasPrintTemplateEntity.setConfigInfo(defaultEntity.getConfigInfo());
            paasPrintTemplateEntity.setDistributorMark(distributorMark);
            insertList.add(paasPrintTemplateEntity);
        }
        if (CollectionUtils.isEmpty(insertList)) {
            return;
        }
        try {
            paasPrintTemplateDao.insertBatch(insertList);
        }  catch (Exception e) {
            LOGGER.error("初始化打印模板失败：",e);
        }
    }


    /**
     * 初始化快捷新建和常用表单
     * @param menuInitDTO
     */
    public void initQuickAndCommon(MenuInitDTO menuInitDTO) throws XbbException {

        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", menuInitDTO.getCorpid());
        param.put("del", DelEnum.NORMAL.getDel());
        param.put("enable", 1);
        List<PaasMenuEntity> menuList = paasMenuModel.findEntitys(param);

        Map<String, PaasMenuEntity> menuMap = new HashMap<>(menuList.size());
        for (PaasMenuEntity paasMenuEntity : menuList) {
            if (StringUtil.isNotEmpty(paasMenuEntity.getAlias())) {
                menuMap.put(paasMenuEntity.getAlias(), paasMenuEntity);
            }
        }
        String corpid = menuInitDTO.getCorpid();
        String dingtalkQuickAlias = UserConfigEnum.QUICK_NEW_FORM.getAlias() + "_" + PlatFormEnum.DINGTALK.getValue();

        String[] quick = MenuConstant.QUICK_NEW_DINGTALK;
        List<String> quickList = Arrays.asList(quick);
        List<MenuReturnPojo> menuIdList = new ArrayList<>();
        for (int i = 0; i < quickList.size(); i++) {
            String s = quickList.get(i);
            if(Objects.nonNull(menuMap.get(s))){
                MenuReturnPojo menuReturnPojo = new MenuReturnPojo();
                menuReturnPojo.setMenuId(menuMap.get(s).getId());
                menuReturnPojo.setParentId(menuMap.get(s).getParentId());
                menuReturnPojo.setName(menuMap.get(s).getName());
                menuReturnPojo.setSort(i);
                menuIdList.add(menuReturnPojo);
            }
        }
        companyConfigModel.save(corpid, dingtalkQuickAlias, UserConfigEnum.QUICK_NEW_FORM.getName(), JSONObject.toJSONString(menuIdList));

        String webQuickAlias = UserConfigEnum.QUICK_NEW_FORM.getAlias() + "_" + PlatFormEnum.WEB.getValue();
        String[] qcQuick = MenuConstant.QUICK_NEW_WEB;
        List<String> pcQuickList = Arrays.asList(qcQuick);
        List<MenuReturnPojo> pcMenuIdList = new ArrayList<>();
        for (int i = 0; i < pcQuickList.size(); i++) {
            String s = pcQuickList.get(i);
            if(Objects.nonNull(menuMap.get(s))){
                MenuReturnPojo menuReturnPojo = new MenuReturnPojo();
                menuReturnPojo.setMenuId(menuMap.get(s).getId());
                menuReturnPojo.setParentId(menuMap.get(s).getParentId());
                menuReturnPojo.setName(menuMap.get(s).getName());
                menuReturnPojo.setSort(i);
                pcMenuIdList.add(menuReturnPojo);
            }
        }
        companyConfigModel.save(corpid, webQuickAlias, UserConfigEnum.QUICK_NEW_FORM.getName(), JSONObject.toJSONString(pcMenuIdList));


        String commonAlias = UserConfigEnum.COMMON_FORM.getAlias();
        String[] commonForm = MenuConstant.COMMON_FORM;
        List<String> commonFormList = Arrays.asList(commonForm);
        List<MenuReturnPojo> commonFormMenuIdList = new ArrayList<>();
        for (int i = 0; i < commonFormList.size(); i++) {
            String s = commonFormList.get(i);
            if(Objects.nonNull(menuMap.get(s))){
                MenuReturnPojo menuReturnPojo = new MenuReturnPojo();
                menuReturnPojo.setMenuId(menuMap.get(s).getId());
                menuReturnPojo.setParentId(menuMap.get(s).getParentId());
                menuReturnPojo.setName(menuMap.get(s).getName());
                menuReturnPojo.setSort(i);
                commonFormMenuIdList.add(menuReturnPojo);
            }
        }
        companyConfigModel.save(corpid, commonAlias, UserConfigEnum.COMMON_FORM.getName(), JSONObject.toJSONString(commonFormMenuIdList));

    }


    /**
     * 初始化资金账户
     * @param menuInitDTO 入参
     * @param distributorMark 经销商标识
     * @throws XbbException error
     * @author zhouwq
     * @date 2020/4/10 15:54
     */
    protected void initFundAccount(MenuInitDTO menuInitDTO, boolean distributorMark) throws XbbException {
        String corpid = menuInitDTO.getCorpid();
        try {
            if (distributorMark) {
                FundAccountEntity entity = fundAccountModel.getDefaultFundAccount(corpid);
                if (entity == null) {
                    BigDecimal decimal = new BigDecimal(0);
                    long now = DateTimeUtil.getLong();
                    entity = new FundAccountEntity(corpid, BasicConstant.ZERO_STRING, "默认账户", 1, decimal, now, decimal, 1);
                }
                entity.setIsWeChatPaymentDefault(1);
                entity.setIsAlipayPaymentDefault(1);
                entity.setIsUnionPayPaymentDefault(1);
                fundAccountModel.save(entity);
            } else {
                fundAccountModel.initFundAccount(Collections.singletonList(corpid));
            }
        } catch (Exception e) {
            LOGGER.error("MenuInitHelp.initFundAccount初始化资金账户出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
    }

    /**
     * 更新资金管理
     * @author 吴峰
     * @date 2019/2/21 14:09
     * @param menuInitDTO
     * @return void
     * @throws XbbException 业务异常
     */
    protected void afterUpdateFundManagementMenu(MenuInitDTO menuInitDTO, Map<String, PaasAppEntity> appMap) throws XbbException {
        try {
            ApplicationUpdateDTO applicationUpdateDTO = new ApplicationUpdateDTO();
            applicationUpdateDTO.setCorpid(menuInitDTO.getCorpid());
            Integer sort = menuInitDTO.getAppMap().get(SystemAppMenuEnum.JXC.getAlias()).getSort();
            PaasAppEntity paasAppEntity = appMap.get(SystemAppMenuEnum.FUND_MANAGEMENT.getAlias());
            applicationUpdateDTO.setId(paasAppEntity.getId());
            applicationUpdateDTO.setSort(sort+1);
            proAppService.updatePaasApp(applicationUpdateDTO);
        } catch (Exception e) {
            LOGGER.error("MenuInitHelp.afterUpdateFundManagementMenu更新资金管理的排序出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
    }

    /**
     * 使用镜像时，开启进销存同步开启产品
     * @param corpid
     * @author xingxing.xiao
     * @date 2019/12/10 20:13
     */
    public void setProductByMirror(String corpid) {
        // 1. 查询是否使用镜像
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("del", 0);
        Integer count = mirrorCompanyModel.getEntitysCount(param);
        if (count > 0) {
            // 2. 开启产品应用
            PaasAppEntity productApp = paasAppModel.getByAlias(SystemAppMenuEnum.PRODUCT.getAlias(), corpid);
            if (productApp != null && Objects.equals(productApp.getEnable(), 0)) {
                productApp.setEnable(BasicConstant.IS_USE);
                paasAppModel.update(productApp);
                // 3. 开启产品菜单
                PaasMenuEntity paasMenuEntity = paasMenuModel.getByAlias(ProductMenuEnum.PRODUCT.getAlias(), productApp.getId(), corpid);
                if (paasMenuEntity != null && Objects.equals(paasMenuEntity.getEnable(), 0)) {
                    paasMenuEntity.setEnable(BasicConstant.IS_USE);
                    paasMenuModel.update(paasMenuEntity);
                    // 4. 开启产品表单和表单解释
                    PaasFormEntityExt formEntity = paasFormModel.getByMenuId(paasMenuEntity.getId(), corpid);
                    if (Objects.nonNull(formEntity) && Objects.equals(formEntity.getEnable(), 0)) {
                        formEntity.setEnable(BasicConstant.IS_USE);
                        paasFormModel.update(formEntity);
                        paasFormExplainModel.updateByFormId(formEntity.getId(), corpid, 1);
                    }
                }
            }
        }
    }



    /**
     * 获取移动端详情默认显示标题
     *
     * @param businessType 业务类型
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/4/8 19:58
     */
    public List<FormTitlePoJo> getAppDefaultTitle(Integer businessType) {
        List<Object> titleAttrList;
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
            case CUSTOMER:
            case CUSTOMER_FOCUS:
            case CUSTOMER_DEAL:
            case CUSTOMER_FOLLOW:
            case CUSTOMER_PUBLIC:
            case CUSTOMER_RECYCLE:
            case CUSTOMER_NEARBY:
                titleAttrList = CustomerManagementEnum.getTitleAttrList();
                break;
            case SALES_OPPORTUNITY:
            case ALL_OPPORTUNITY:
            case KEY_OPPORTUNITY:
                titleAttrList = SalesOpportunityEnum.getTitleAttrList();
                break;
            case WORK_REPORT:
                titleAttrList = WorkReportEnum.getTitleAttrList();
                break;
            case CONTACT:
                titleAttrList = ContactEnum.getTitleAttrList();
                break;
            case CONTRACT:
                titleAttrList = ContractEnum.getTitleAttrList();
                break;
            case PURCHASE:
                titleAttrList = PurchaseEnum.getTitleAttrList();
                break;
            case SUPPLIER:
                titleAttrList = SupplierEnum.getTitleAttrList();
                break;
            case WAREHOUSE:
                titleAttrList = WarehouseEnum.getTitleAttrList();
                break;
            case SUPPLIER_CONTACT:
                titleAttrList = SupplierContactEnum.getTitleAttrList();
                break;
            case PRODUCTION_ORDER:
                titleAttrList = ProductionOrderEnum.getTitleAttrList();
                break;
            case BOM_BILL:
                titleAttrList = BomBillEnum.getTitleAttrList();
                break;
            case RETURNED_PURCHASE:
                titleAttrList = ReturnedPurchaseEnum.getTitleAttrList();
                break;
            case OTHER_INSTOCK:
            case INSTOCK:
                titleAttrList = InstockEnum.getTitleAttrList();
                break;
            case PURCHASE_INSTOCK:
                titleAttrList = PurchaseInstockEnum.getTitleAttrList();
                break;
            case REFUND_INSTOCK:
                titleAttrList = RefundInstockEnum.getTitleAttrList();
                break;
            case PRODUCTION_INSTOCK:
                titleAttrList = ProductionInstockEnum.getTitleAttrList();
                break;
            case RETURNED_MATERIEL_INSTOCK:
                titleAttrList = ReturnedMaterielInstockEnum.getTitleAttrList();
                break;
            case OTHER_OUTSTOCK:
            case OUTSTOCK:
                titleAttrList = OutstockEnum.getTitleAttrList();
                break;
            case WORK_ORDER_OUTSTOCK:
                titleAttrList = WorkOrderOutstockEnum.getTitleAttrList();
                break;
            case CONTRACT_OUTSTOCK:
                titleAttrList = ContractOutstockEnum.getTitleAttrList();
                break;
            case RETURNED_PURCHASE_OUTSTOCK:
                titleAttrList = ReturnedPurchaseOutstockEnum.getTitleAttrList();
                break;
            case PRODUCTION_MATERIEL_OUTSTOCK:
                titleAttrList = ProductionMaterielOutstockEnum.getTitleAttrList();
                break;
            case INVENTORY:
                titleAttrList = InventoryEnum.getTitleAttrList();
                break;
            case TRANSFER:
                titleAttrList = TransferEnum.getTitleAttrList();
                break;
            case ASSEMBLE:
                titleAttrList = AssembleEnum.getTitleAttrList();
                break;
            case INVOICE:
                titleAttrList = InvoiceEnum.getTitleAttrList();
                break;
            case PURCHASE_INVOICE:
                titleAttrList = PurchaseInvoiceEnum.getTitleAttrList();
                break;
            case PAYMENT:
                titleAttrList = PaymentEnum.getTitleAttrList();
                break;
            case PAY_PLAN:
                titleAttrList = PayPlanEnum.getTitleAttrList();
                break;
            case PRODUCT:
                titleAttrList = ProductEnum.getTitleAttrList();
                break;
            case COMMUNICATE_PLAN:
                titleAttrList = CommunicatePlanEnum.getTitleAttrList();
                break;
            case REFUND:
                titleAttrList = RefundEnum.getTitleAttrList();
                break;
            case QUOTATION:
                titleAttrList = QuotationEnum.getTitleAttrList();
                break;
            case PREPAYMENT_BALANCE:
                titleAttrList = PaymentBalanceEnum.getTitleAttrList();
                break;
            case PAYMENT_SHEET:
                titleAttrList = PaymentSheetEnum.getTitleAttrList();
                break;
            case ONLINE_PAYMENT_FLOW:
                titleAttrList = OnlinePaymentFlowDistributorEnum.getTitleAttrList();
                break;
            case REIMBURSEMENT_FORM:
                titleAttrList = ReimbursementFormEnum.getTitleAttrList();
                break;
            case EXPENSE:
                titleAttrList = ExpenseEnum.getTitleAttrList();
                break;
            case PAY_SHEET:
                titleAttrList = PaySheetEnum.getTitleAttrList();
                break;
            case PREPAY_BALANCE:
                titleAttrList = PayBalanceEnum.getTitleAttrList();
                break;
            case OTHER_INCOME:
                titleAttrList = OtherIncomeEnum.getTitleAttrList();
                break;
            case OTHER_EXPENSE:
                titleAttrList = OtherExpenseEnum.getTitleAttrList();
                break;
            case FUND_TRANSFER:
                titleAttrList = FundTransferEnum.getTitleAttrList();
                break;
            case CREDIT_LIMIT:
                titleAttrList = CreditLimitEnum.getTitleAttrList();
                break;
            case CREDIT_FIXED_LIMIT:
                titleAttrList = CreditFixedLimitEnum.getTitleAttrList();
                break;
            case CREDIT_TEMPORARY_LIMIT:
                titleAttrList = CreditTemporaryLimitEnum.getTitleAttrList();
                break;
            case CREDIT_CARD_BILL:
                titleAttrList = CreditCardBillEnum.getTitleAttrList();
                break;
            case PAYMENT_TASK:
                titleAttrList = PaymentTaskEnum.getTitleAttrList();
                break;
            case DISTRIBUTOR_MANAGEMENT:
                titleAttrList = DistributorEnum.getTitleAttrList();
                break;
            case DISTRIBUTOR_CONTACT:
                titleAttrList = DistributorContactEnum.getTitleAttrList();
                break;
            case DISTRIBUTOR_ACCOUNT:
                titleAttrList = DistributorAccountEnum.getTitleAttrList();
                break;
            case MARKET_ACTIVITY:
                titleAttrList = MarketActivityEnum.getTitleAttrList();
                break;
            case CLUE:
                titleAttrList = ClueEnum.getTitleAttrList();
                break;
            case COST_ADJUST:
                titleAttrList = CostAdjustEnum.getTitleAttrList();
                break;
            case COMPETITOR:
                titleAttrList = CompetitorEnum.getTitleAttrList();
                break;
            case RECEIPT_ORDER:
                titleAttrList = ReceiptOrderEnum.getTitleAttrList();
                break;
            default:
                titleAttrList = new ArrayList<>();
                break;
        }
        List<FormTitlePoJo> formTitlePoJoList = new ArrayList<>();
        for (Object object : titleAttrList) {
            if (Objects.nonNull(object)) {
                Object attr;
                Object attrName;
                if (object instanceof JSONObject) {
                    JSONObject itemObj = (JSONObject) object;
                    attr = itemObj.get("attr");
                    attrName = itemObj.get("attrName");
                } else {
                    attr = ReflectHelper.valueGet(object, "attr");
                    attrName = ReflectHelper.valueGet(object, "attrName");
                }
                FormTitlePoJo formTitlePoJo = new FormTitlePoJo();
                if (Objects.nonNull(attr)) {
                    ReflectHelper.valueSet(formTitlePoJo, "attr", attr);
                }
                if (Objects.nonNull(attrName)) {
                    ReflectHelper.valueSet(formTitlePoJo, "attrName", attrName);
                }
                formTitlePoJoList.add(formTitlePoJo);
            }
        }
        return formTitlePoJoList;
    }

    /**
     * 获取表单默认label 移动端详情页展示
     *
     * @param businessType 业务类型
     * @author GuoJun.HU
     * @since V1.0
     * @return List
     * @date 2019/4/8 19:40
     */
    public List<SummaryDataPoJo> getAppDefaultLabel(Integer businessType) {
        List<Object> labelAttrList;
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
            case CUSTOMER:
            case CUSTOMER_FOCUS:
            case CUSTOMER_DEAL:
            case CUSTOMER_FOLLOW:
            case CUSTOMER_PUBLIC:
            case CUSTOMER_RECYCLE:
            case CUSTOMER_NEARBY:
                labelAttrList = CustomerManagementEnum.getLabelAttrList();
                break;
            case CONTACT:
                labelAttrList = ContactEnum.getLabelAttrList();
                break;
            case CONTRACT:
                labelAttrList = ContractEnum.getLabelAttrList();
                break;
            case SUPPLIER_CONTACT:
                labelAttrList = SupplierContactEnum.getLabelAttrList();
                break;
            case PURCHASE:
                labelAttrList = PurchaseEnum.getLabelAttrList();
                break;
            case QUOTATION:
                labelAttrList = QuotationEnum.getLabelAttrList();
                break;
            case OTHER_INSTOCK:
                labelAttrList = InstockEnum.getLabelAttrList();
                break;
            case PURCHASE_INSTOCK:
                labelAttrList = PurchaseInstockEnum.getLabelAttrList();
                break;
            case REFUND_INSTOCK:
                labelAttrList = RefundInstockEnum.getLabelAttrList();
                break;
            case PRODUCTION_INSTOCK:
                labelAttrList = ProductionInstockEnum.getLabelAttrList();
                break;
            case RETURNED_MATERIEL_INSTOCK:
                labelAttrList = ReturnedMaterielInstockEnum.getLabelAttrList();
                break;
            case CONTRACT_OUTSTOCK:
                labelAttrList = ContractOutstockEnum.getLabelAttrList();
                break;
            case RETURNED_PURCHASE_OUTSTOCK:
                labelAttrList = ReturnedPurchaseOutstockEnum.getLabelAttrList();
                break;
            case PRODUCTION_MATERIEL_OUTSTOCK:
                labelAttrList = ProductionMaterielOutstockEnum.getLabelAttrList();
                break;
            case WORK_ORDER_OUTSTOCK:
                labelAttrList = WorkOrderOutstockEnum.getLabelAttrList();
                break;
            case OTHER_OUTSTOCK:
                labelAttrList = OutstockEnum.getLabelAttrList();
                break;
            case PREPAYMENT_BALANCE:
                labelAttrList = PaymentBalanceEnum.getLabelAttrList();
                break;
            case CREDIT_LIMIT:
                labelAttrList = CreditLimitEnum.getLabelAttrList();
                break;
            case CREDIT_TEMPORARY_LIMIT:
                labelAttrList = CreditTemporaryLimitEnum.getLabelAttrList();
                break;
            case PREPAY_BALANCE:
                labelAttrList = PayBalanceEnum.getLabelAttrList();
                break;
            case MARKET_ACTIVITY:
                labelAttrList = MarketActivityEnum.getLabelAttrList();
                break;
            case CLUE:
                labelAttrList = ClueEnum.getLabelAttrList();
                break;
            case DISTRIBUTOR_MANAGEMENT:
                labelAttrList = DistributorEnum.getLabelAttrList();
                break;
            case DISTRIBUTOR_CONTACT:
                labelAttrList = DistributorContactEnum.getLabelAttrList();
                break;
            case COST_ADJUST:
                labelAttrList = CostAdjustEnum.getLabelAttrList();
                break;
            case COMPETITOR:
                labelAttrList = CompetitorEnum.getLabelAttrList();
                break;
            case RECEIPT_ORDER:
                labelAttrList = ReceiptOrderEnum.getLabelAttrList();
                break;
            default:
                labelAttrList = new ArrayList<>();
                break;
        }
        List<SummaryDataPoJo> summaryDataPoJoList = new ArrayList<>();
        for (Object object : labelAttrList) {
            if (Objects.nonNull(object)) {
                Object attr;
                Object attrName;
                Object fieldType;
                if (object instanceof JSONObject) {
                    JSONObject itemObj = (JSONObject) object;
                    attr = itemObj.get("attr");
                    attrName = itemObj.get("attrName");
                    fieldType = itemObj.get("fieldType");
                } else {
                    attr = ReflectHelper.valueGet(object, "attr");
                    attrName = ReflectHelper.valueGet(object, "attrName");
                    fieldType = ReflectHelper.valueGet(object, "fieldType");
                }
                SummaryDataPoJo summaryDataPoJo = new SummaryDataPoJo();
                if (Objects.nonNull(attr)) {
                    ReflectHelper.valueSet(summaryDataPoJo, "attr", attr);
                }
                if (Objects.nonNull(attrName)) {
                    ReflectHelper.valueSet(summaryDataPoJo, "attrName", attrName);
                }
                if (Objects.nonNull(fieldType)) {
                    ReflectHelper.valueSet(summaryDataPoJo, "fieldType", fieldType);
                }
                summaryDataPoJoList.add(summaryDataPoJo);
            }
        }
        return summaryDataPoJoList;
    }

    /**
     * 获取表单默认label 移动端详情页展示
     *
     * @param businessType 业务类型
     * @author GuoJun.HU
     * @since V1.0
     * @return List
     * @date 2019/4/8 19:40
     */
    public List<SummaryDataPoJo> getAppDefaultSummary(Integer businessType) {
        List<Object> summaryList;
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
            case CUSTOMER:
            case CUSTOMER_FOCUS:
            case CUSTOMER_DEAL:
            case CUSTOMER_FOLLOW:
            case CUSTOMER_PUBLIC:
            case CUSTOMER_RECYCLE:
            case CUSTOMER_NEARBY:
                summaryList = CustomerManagementEnum.getSummaryAttrList();
                break;
            case CONTACT:
                summaryList = ContactEnum.getSummaryAttrList();
                break;
            case SALES_OPPORTUNITY:
            case ALL_OPPORTUNITY:
            case KEY_OPPORTUNITY:
                summaryList = SalesOpportunityEnum.getSummaryAttrList();
                break;
            case CONTRACT:
                summaryList = ContractEnum.getSummaryAttrList();
                break;
            case REFUND:
                summaryList = RefundEnum.getSummaryAttrList();
                break;
            case PAYMENT:
                summaryList = PaymentEnum.getSummaryAttrList();
                break;
            case PAY_PLAN:
                summaryList = PayPlanEnum.getSummaryAttrList();
                break;
            case INVOICE:
                summaryList = InvoiceEnum.getSummaryAttrList();
                break;
            case PURCHASE_INVOICE:
                summaryList = PurchaseInvoiceEnum.getSummaryAttrList();
                break;
            case CREDIT_LIMIT:
                summaryList = CreditLimitEnum.getSummaryAttrList();
                break;
            case CREDIT_FIXED_LIMIT:
                summaryList = CreditFixedLimitEnum.getSummaryAttrList();
                break;
            case CREDIT_TEMPORARY_LIMIT:
                summaryList = CreditTemporaryLimitEnum.getSummaryAttrList();
                break;
            case CREDIT_CARD_BILL:
                summaryList = CreditCardBillEnum.getSummaryAttrList();
                break;
            case SUPPLIER:
                summaryList = SupplierEnum.getSummaryAttrList();
                break;
            case SUPPLIER_CONTACT:
                summaryList = SupplierContactEnum.getSummaryAttrList();
                break;
            case PURCHASE:
                summaryList = PurchaseEnum.getSummaryAttrList();
                break;
            case RETURNED_PURCHASE:
                summaryList = ReturnedPurchaseEnum.getSummaryAttrList();
                break;
            case INSTOCK:
            case PURCHASE_INSTOCK:
            case REFUND_INSTOCK:
            case OTHER_INSTOCK:
            case PRODUCTION_INSTOCK:
            case RETURNED_MATERIEL_INSTOCK:
                summaryList = InstockEnum.getSummaryAttrList();
                break;
            case OUTSTOCK:
            case CONTRACT_OUTSTOCK:
            case RETURNED_PURCHASE_OUTSTOCK:
            case OTHER_OUTSTOCK:
            case PRODUCTION_MATERIEL_OUTSTOCK:
            case WORK_ORDER_OUTSTOCK:
                summaryList = OutstockEnum.getSummaryAttrList();
                break;
            case INVENTORY:
                summaryList = InventoryEnum.getSummaryAttrList();
                break;
            case TRANSFER:
                summaryList = TransferEnum.getSummaryAttrList();
                break;
            case ASSEMBLE:
                summaryList = AssembleEnum.getSummaryAttrList();
                break;
            case WAREHOUSE:
                summaryList = WarehouseEnum.getSummaryAttrList();
                break;
            case BOM_BILL:
                summaryList = BomBillEnum.getSummaryAttrList();
                break;
            case PRODUCTION_ORDER:
                summaryList = ProductionOrderEnum.getSummaryAttrList();
                break;
            case COMMUNICATE_PLAN:
                summaryList = CommunicatePlanEnum.getSummaryAttrList();
                break;
            case PRODUCT:
                summaryList = ProductEnum.getSummaryAttrList();
                break;
            case QUOTATION:
                summaryList = QuotationEnum.getSummaryAttrList();
                break;
            case PREPAYMENT_BALANCE:
                summaryList = PaymentBalanceEnum.getSummaryAttrList();
                break;
            case PAYMENT_SHEET:
                summaryList = PaymentSheetEnum.getSummaryAttrList();
                break;
            case ONLINE_PAYMENT_FLOW:
                summaryList = OnlinePaymentFlowDistributorEnum.getSummaryAttrList();
                break;
            case REIMBURSEMENT_FORM:
                summaryList = ReimbursementFormEnum.getSummaryAttrList();
                break;
            case EXPENSE:
                summaryList = ExpenseEnum.getSummaryAttrList();
                break;
            case PAY_SHEET:
                summaryList = PaySheetEnum.getSummaryAttrList();
                break;
            case PREPAY_BALANCE:
                summaryList = PayBalanceEnum.getSummaryAttrList();
                break;
            case OTHER_INCOME:
                summaryList = OtherIncomeEnum.getSummaryAttrList();
                break;
            case OTHER_EXPENSE:
                summaryList = OtherExpenseEnum.getSummaryAttrList();
                break;
            case FUND_TRANSFER:
                summaryList = FundTransferEnum.getSummaryAttrList();
                break;
            case MARKET_ACTIVITY:
                summaryList = MarketActivityEnum.getSummaryAttrList();
                break;
            case CLUE:
                summaryList = ClueEnum.getSummaryAttrList();
                break;
            case PAYMENT_TASK:
                summaryList = PaymentTaskEnum.getSummaryAttrList();
                break;
            case DISTRIBUTOR_MANAGEMENT:
                summaryList = DistributorEnum.getSummaryAttrList();
                break;
            case DISTRIBUTOR_CONTACT:
                summaryList = DistributorContactEnum.getSummaryAttrList();
                break;
            case DISTRIBUTOR_ACCOUNT:
                summaryList = DistributorAccountEnum.getSummaryAttrList();
                break;
            case COST_ADJUST:
                summaryList = CostAdjustEnum.getSummaryAttrList();
                break;
            case COMPETITOR:
                summaryList = CompetitorEnum.getSummaryAttrList();
                break;
            case COMPETITOR_ANALYSIS:
                summaryList = CompetitorAnalysisEnum.getSummaryAttrList();
                break;
            case RECEIPT_ORDER:
                summaryList = ReceiptOrderEnum.getSummaryAttrList();
                break;
            default:
                summaryList = new ArrayList<>();
                break;
        }
        List<SummaryDataPoJo> summaryDataPoJoList = new ArrayList<>();
        for (Object object : summaryList) {
            if (Objects.nonNull(object)) {
                Object attr;
                Object attrName;
                Object fieldType;
                if (object instanceof JSONObject) {
                    JSONObject itemObj = (JSONObject) object;
                    attr = itemObj.get("attr");
                    attrName = itemObj.get("attrName");
                    fieldType = itemObj.get("fieldType");
                } else {
                    attr = ReflectHelper.valueGet(object, "attr");
                    attrName = ReflectHelper.valueGet(object, "attrName");
                    fieldType = ReflectHelper.valueGet(object, "fieldType");
                }
                SummaryDataPoJo summaryDataPoJo = new SummaryDataPoJo();
                if (Objects.nonNull(attr)) {
                    ReflectHelper.valueSet(summaryDataPoJo, "attr", attr);
                }
                if (Objects.nonNull(attrName)) {
                    ReflectHelper.valueSet(summaryDataPoJo, "attrName", attrName);
                }
                if (Objects.nonNull(fieldType)) {
                    ReflectHelper.valueSet(summaryDataPoJo, "fieldType", fieldType);
                }
                summaryDataPoJoList.add(summaryDataPoJo);
            }
        }
        return summaryDataPoJoList;
    }
}
